package com.khyr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.entity.Menu;
import com.khyr.entity.RoleMenu;
import com.khyr.service.MenuService;
import com.khyr.vo.MenuVo;
import com.khyr.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋一恒
 * @version 1.0
 */

@RestController
@RequestMapping("/systemManager/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    //查询所有菜单
    @GetMapping("/selectAllMenu")
    public R<List<Menu>> selectAllMenu() {
        return menuService.selectAllMenu();
    }
    //条件查询
    @PostMapping("/findMenuByCond")
    public R<Page<Menu>> findMenuByCond(@RequestBody MenuVo menuVo) {
        System.out.println(menuVo.getPageNum());
        return menuService.findMenuByCond(menuVo);
    }

    //添加
    @PostMapping("/addMenu")
    public R<Integer> addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }

    //修改
    @PostMapping("/updateMenu")
    public R<Integer> updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }
    //根据id查询
    @PostMapping("/getMenuById/{id}")
    public R<Menu> getMenuById(@PathVariable Long id){
        return menuService.getMenuById(id);
    }
    //删除
    @DeleteMapping("/deleteMenuById/{id}")
    public R<Integer> deleteMenuById(@PathVariable Long id){
        return menuService.deleteMenuById(id);
    }

    @GetMapping("/selectMenusByRoleId/{roleId}")
    public R<List<RoleMenu>> selectMenusByRoleId(@PathVariable Long roleId){
        return menuService.selectMenusByRoleId(roleId);
    }


}
